package com.ellricky.excute_president.ui.fragment

import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import com.andr.common.http.callback.BaseCallback
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.http.callback.EListCallback
import com.ellricky.baselib.ui.base.BaseRefreshFragment
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.excute_president.*
import com.ellricky.excute_president.API_AM_MEETING_LIST
import com.ellricky.excute_president.AmMeetingAdapter
import com.ellricky.excute_president.ui.activity.meet.AmMeetingDetailActivity

class AmMeetingRecordFragment : BaseRefreshFragment<Void, BasePresenter<Void>, AmMeetingRecordEntity>() {


    companion object {
        fun newInstance(): AmMeetingRecordFragment {
            val fragment = AmMeetingRecordFragment()
            val bundle = Bundle()
            fragment.arguments = bundle
            return fragment
        }
    }


    override fun initUIView(root: View) {
        super.initUIView(root)
        mTvTitle.setText(R.string.pd_am_record)
        setRightBtn(0)
    }


    override fun getRvAdapter(): BaseRecyclerAdapter<AmMeetingRecordEntity> {
        return AmMeetingAdapter(mContext)
    }

    override fun getResponseCallback(): BaseCallback {
        return object : EListCallback<AmMeetingRecordEntity>(mContext) {
            override fun onSuccess(data: MutableList<AmMeetingRecordEntity>?, msg: String?) {
                dataSource = data
                rvView.onLoadFinish(dataSource, refresh)
            }

            override fun onErrorCode(code: String?, msg: String?) {
                super.onErrorCode(code, msg)
                rvView.onRefreshFailed(refresh)
            }

            override fun onHttpError(code: String?, msg: String?) {
                super.onHttpError(code, msg)
                rvView.onRefreshFailed(refresh)
            }
        }
    }

    override fun getUrlPath(): String {
        return API_AM_MEETING_LIST
    }


    override fun onItemClick(adapterView: AdapterView<*>?, view: View?, i: Int, l: Long) {
        super.onItemClick(adapterView, view, i, l)
        EAppUtil.jumpPageWithId(
                mContext, AmMeetingDetailActivity::class.java, adapter.get(i).id
        )
    }

    override fun onClickBtnRight() {
        super.onClickBtnRight()
        jumpAmMeetAdd(this)
    }


}
